<?php
	function alertMonth($text,$color,$icon)
	{
		$colors = array
		(
			'red'=>'#ff0000',
			'yellow'=>'#FFFB00',
			'green'=>'#00ff00',
		);
		$icons = array
		(
			'family'=>'images/family_super_small.png',
			'business'=>'images/briefcase_super_small.png',
			'pleasure'=>'images/coffee_super_small.png',
		);
		return 
		'<HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle" backgroundColor="'.$colors[$color].'" backgroundAlpha="0.3" cornerRadius="2" click="dispatchEvent(viewstack1, \'eventpreview\')">
			<Text text="'.$text.'"/>
			<Image source="'.$icons[$icon].'" width="20" height="20" />
		</HBox>';
	}
	function checkMonthAlert($day,$hour)
	{
		$events = array
		(
			1=>array
			(
				5=>array('Sleep','green','pleasure'),
				8=>array('Go to work','yellow','business')
			),
			5=>array
			(
				12=>array('Go to Job Interview','yellow','business'),
				15=>array('See Cousin','red','family')
			),
			9=>array
			(
				4=>array('Take a Photo','green','pleasure'),
				12=>array('Eat lunch','red','pleasure')
			),
			12=>array
			(
				6=>array('Go jogging','yellow','pleasure'),
				14=>array('Take a nap','red','family')
			),
		);
		#$events = array();
		if(isset($events[$day][$hour]))
		{
			return alertMonth
			(
				$events[$day][$hour][0],
				$events[$day][$hour][1],
				$events[$day][$hour][2]
			);
		}
		return '';
	}

?>
<Canvas label="Month per hour" width="100%" height="100%">
	<Grid borderStyle="none" width="95%" verticalGap="0" horizontalGap="0" backgroundColor="#eeeeee" backgroundAlpha="0.5">
		<GridRow backgroundColor="#f0f0f0">
			<GridItem width="50"><Text text=""/></GridItem>
			<?php
				for($i=1;$i<=date('t');$i++)
				{
					if(date('N',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))) > 5)
					{
						?><GridItem width="150" height="40" horizontalAlign="center" verticalAlign="middle" backgroundColor="#e0e0e0">
							<Text text="<?php echo $i.' '.(date('M')).' '.date('l',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))); ?>" />
						</GridItem><?php
					}
					else
					{
						?><GridItem width="150" height="40" horizontalAlign="center" verticalAlign="middle" backgroundColor="#f0f0f0">
							<Text text="<?php echo $i.' '.(date('M')).' '.date('l',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))); ?>" />
						</GridItem><?php
					}
				}
			?>
		</GridRow>
		<?php
			for($j=0;$j<=23;$j++)
			{
				?><GridRow backgroundColor="#f0f0f0">
					<GridItem width="50"><Text text="<?php echo $j; ?>:00"/></GridItem>
					<?php
						if($j % 2)
						{
							for($i=1;$i<=date('t');$i++)
							{
								if
								(
									date('N',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))) == 7 ||
									date('N',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))) == 1
								)
								{
									?><GridItem width="150"  height="30" horizontalAlign="center" verticalAlign="middle" backgroundColor="#c0c0c0">
										<?php echo checkMonthAlert($i,$j); ?>
									</GridItem><?php
								}
								else
								{
									?><GridItem width="150" height="30" horizontalAlign="center" verticalAlign="middle" backgroundColor="#e0e0e0">
										<?php echo checkMonthAlert($i,$j); ?>
									</GridItem><?php
								}
							}
						}
						else
						{
							for($i=1;$i<=date('t');$i++)
							{
								if
								(
									date('N',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))) == 7 ||
									date('N',strtotime(($i<10?'0':'').$i.'-'.(date('m')).'-'.date('Y'))) == 1
								)
								{
									?><GridItem width="150" height="40" horizontalAlign="center" verticalAlign="middle" backgroundColor="#d0d0d0">
										<?php echo checkMonthAlert($i,$j); ?>
									</GridItem><?php
								}
								else
								{
									?><GridItem width="150" height="40" horizontalAlign="center" verticalAlign="middle" backgroundColor="#f0f0f0">
										<?php echo checkMonthAlert($i,$j); ?>
									</GridItem><?php
								}
							}
						}
					?>
				</GridRow><?php
			}
		?>
	</Grid>
</Canvas>